//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package xml;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;
import util.Unicode;

public class XmlUtil {
    public XmlUtil() {
    }
    
    public static void write(Map<String, String> map, String filename) {
        Document doc = DocumentHelper.createDocument();
        doc.setXMLEncoding("utf-8");
        Element root = doc.addElement("root");
        Iterator var5 = map.keySet().iterator();
        
        while(var5.hasNext()) {
            String key = (String)var5.next();
            Element mapElement = root.addElement("map");
            mapElement.addAttribute("key", key);
            mapElement.addAttribute("value", Unicode.toUnicodeString((String)map.get(key)));
        }
        
        File directory = new File("");
        writeXml(directory.getAbsolutePath() + "\\" + filename, doc);
    }
    
    public static Map<String, String> read(String filename) {
        File directory = new File("");
        Map<String, String> map = new HashMap();
        SAXReader reader = new SAXReader();
        
        try {
            Document doc = reader.read(directory.getAbsolutePath() + "\\" + filename);
            Element rootElement = doc.getRootElement();
            List<Element> elements = rootElement.elements();
            Iterator var8 = elements.iterator();
            
            while(var8.hasNext()) {
                Element element = (Element)var8.next();
                map.put(element.attributeValue("key"), Unicode.decodeUnicode(element.attributeValue("value")));
            }
        } catch (DocumentException var9) {
            var9.printStackTrace();
        }
        
        return map;
    }
    
    public static Map<String, String> readNu(String filename) {
        File directory = new File("");
        Map<String, String> map = new HashMap();
        SAXReader reader = new SAXReader();
        
        try {
            Document doc = reader.read(directory.getAbsolutePath() + "\\" + filename);
            Element rootElement = doc.getRootElement();
            List<Element> elements = rootElement.elements();
            Iterator var8 = elements.iterator();
            
            while(var8.hasNext()) {
                Element element = (Element)var8.next();
                map.put(element.attributeValue("key"), element.attributeValue("value"));
            }
        } catch (DocumentException var9) {
            var9.printStackTrace();
        }
        
        return map;
    }
    
    private static void writeXml(String outPath, Document doc) {
        try {
            OutputFormat format = OutputFormat.createPrettyPrint();
            format.setEncoding("UTF-8");
            XMLWriter writer = null;
            File file = new File(outPath);
            if (!file.getParentFile().exists()) {
                file.getParentFile().mkdirs();
            }
            
            writer = new XMLWriter(new FileWriter(file), format);
            writer.write(doc);
            writer.close();
        } catch (IOException var5) {
        }
        
    }
}
